﻿using System;
using System.Data;
using System.Data.SqlClient;
using ebay.Dal;

public partial class UI_Mail_FeedbackFollowUp : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e) {
        if (!IsPostBack) {
            String act = Request["act"];
            String type = Request["type"];
            String level = Request["level"];

            if (String.IsNullOrEmpty(act))
                return;

            switch (act) {
                case "i":
                    break;
                case "u":
                    this.txtType.Text = type;
                    this.txtLevel.Text = level;
                    break;
            }
        }
    }

    protected void ButtonSave_Click(object sender, EventArgs e) {
        String act = Request["act"];
        String id = Request["id"];
        String type = txtType.Text;
        String level = txtLevel.Text;
        String sqlString = String.Empty;
        SqlParameter[] parameters = null;

        switch (act.ToLower()) {
            case "i": {
                    sqlString = "INSERT eBayFeedbackFollowType(Type,Level) VALUES(@Type,@Level)";
                    parameters = new SqlParameter[] {
                        new SqlParameter() { ParameterName = "@Type", SqlDbType = SqlDbType.VarChar, Size = 50, Value = type },
                        new SqlParameter() { ParameterName = "@Level", SqlDbType = SqlDbType.VarChar, Size = 50, Value = level }
                    };

                    int val = SqlHelper.ExecuteNonQuery(SqlHelper.ceterDB_Conn, CommandType.Text, sqlString, parameters);
                    if (val > 0) {
                        Page.ClientScript.RegisterStartupScript(Page.GetType(), "Success","<script>alert('新增成功!');window.location.href='Config.aspx'</script>");
                    }
                }
                break;
            case "u": {
                    sqlString = "UPDATE eBayFeedbackFollowType SET Type=@Type,Level=@Level WHERE ID=@ID";
                    parameters = new SqlParameter[] {
                        new SqlParameter() { ParameterName = "@ID", SqlDbType = SqlDbType.Int, Value = id },
                        new SqlParameter() { ParameterName = "@Type", SqlDbType = SqlDbType.VarChar, Size = 50, Value = type },
                        new SqlParameter() { ParameterName = "@Level", SqlDbType = SqlDbType.VarChar, Size = 50, Value = level }
                    };
                    int val = SqlHelper.ExecuteNonQuery(SqlHelper.ceterDB_Conn, CommandType.Text, sqlString, parameters);
                    if (val > 0) {
                        Page.ClientScript.RegisterStartupScript(Page.GetType(), "Success", "<script>alert('修改成功!');window.location.href='Config.aspx'</script>");
                    }
                }
                break;
            default:
                return;
        }
    }
}
